<template>
  <Chart id="operatingCosts" :option="option" v-bind="$attrs"></Chart>
</template>

<script>
import Chart from "@/components/chart/chart.vue";
import { getChartData } from "@/api/echarts";
export default {
  name: "operatingCosts",
  components: { Chart },
  props: [],
  data() {
    return {
      option: {},
      chartData: []
    };
  },
  mounted() {

    getChartData(
      { "custom_chart_id": "4" }
    ).then(res => {
      this.chartData = res.data.data;
      console.log(11, '11111111111');
      this.setOption();
    });
  },
  methods: {
    setOption() {
      this.option = {
        title: {
          // text: "Stacked Area Chart",
        },
        dataset: [
          {
            dimensions: ['name', 'value1', 'value2', 'value3', 'value4', 'value5'],
            source: this.chartData
          },

        ],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        legend: {
          data: ["揽收总成本", "干线总成本", "配送总成本", "回单总成本", "回箱总成本"],
        },
        grid: {
          left: "3%",
          right: "32px",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            gridIndex: 0, 
            // data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
          },
        ],
        yAxis: [
          {
            type: "value",
            label: {
              show: true,
              position: 'top'
            },
          },
        ],
        series: [
          {
            name: "揽收总成本",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            // data: [120, 132, 101, 134, 90, 230, 210],
          },
          {
            name: "干线总成本",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            // data: [220, 182, 191, 234, 290, 330, 310],
          },
          {
            name: "配送总成本",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            // data: [150, 232, 201, 154, 190, 330, 410],
          },
          {
            name: "回单总成本",
            type: "line",
            stack: "Total",
            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            // data: [320, 332, 301, 334, 390, 330, 320],
          },
          {
            name: "回箱总成本",
            type: "line",
            stack: "Total",
            label: {
              show: true,   // 计算的总数
              position: 'top',
              formatter: function (params) {
                return params.value.value;
              },
              color: '#000'
              // textStyle: { color: '#000' }
              // normal: {       // 重写未完成label，通过计算属性重新给formatter赋值，返回

              // }
            },

            areaStyle: {},
            emphasis: {
              focus: "series",
            },
            // data: [820, 932, 901, 934, 1290, 1330, 1320],
          },
          // {
          //   name: "回箱总成本11",
          //   type: "line",
          //   stack: "Total",
          //      label: {
          //     show: true,
          //     position: "top",
          //   },
          //   // label: {
          //   //   show: true,
          //   //   position: "top",
          //   // },
          //   areaStyle: {},
          //   emphasis: {
          //     focus: "series",
          //   },
          //   // data: [20, 32, 91, 34, 129, 133, 132]
          //   // data: [820, 932, 901, 934, 1290, 1330, 1320],
          // },
        ],
      };
    },
  },
};
</script>
<style lang="scss" scoped>
.wrapper {}
</style>
